package com.zitangkou.user.service.impl;

import com.zitangkou.user.entity.EnterpriseDo;
import com.zitangkou.common.enums.StatusEnum;
import com.zitangkou.common.global.PageResp;
import com.zitangkou.user.mapper.EnterpriseMapper;
import com.zitangkou.user.req.enterprise.AddEnterpriseReq;
import com.zitangkou.user.req.enterprise.EditEnterpriseReq;
import com.zitangkou.user.req.enterprise.GetEnterpriseByPageReq;
import com.zitangkou.user.service.IEnterpriseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * 用户
 *
 * @author Deng Ningning
 * @version 1.0
 * @date 2020/8/31 16:39
 */

@Slf4j
@Service
public class EnterpriseServiceImpl implements IEnterpriseService {

    private final EnterpriseMapper enterpriseMapper;

    @Autowired
    public EnterpriseServiceImpl(EnterpriseMapper enterpriseMapper) {
        this.enterpriseMapper = enterpriseMapper;
    }

    /**
     * 分页查询企业
     *
     * @param req
     * @return com.zitangkou.common.global.PageResp<com.zitangkou.user.model.entity.EnterpriseDO>
     * @author Deng Ningning
     * @date 2020/9/1 17:19
     */
    @Override
    public PageResp<EnterpriseDo> selectByPage(GetEnterpriseByPageReq req) {
        return new PageResp<EnterpriseDo>()
                .setList(enterpriseMapper.selectEnterpriseByPage(req))
                .setTotal(enterpriseMapper.countEnterpriseByPage(req));
    }

    @Override
    public boolean insertEnterprise(AddEnterpriseReq req) {
        EnterpriseDo enterpriseDO = new EnterpriseDo();
        BeanUtils.copyProperties(req, enterpriseDO);
        enterpriseDO.setStatus(StatusEnum.ENABLED);
        enterpriseDO.setCreateTime(LocalDateTime.now());
        return enterpriseMapper.insert(enterpriseDO) > 0;
    }

    @Override
    public boolean updateEnterprise(EditEnterpriseReq req) {
        return false;
    }

    @Override
    public boolean deleteEnterprise(String enterpriseId) {
        return false;
    }

    @Override
    public EnterpriseDo selectById(String enterpriseId) {
        return enterpriseMapper.selectById(enterpriseId);
    }
}
